package com.training1.core.web.controller;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.training1.core.common.controller.BaseController;
import com.training1.core.common.global.signIn.BOXLoginInfoUtil;
import com.training1.core.entity.ContractBaseEntity;
import com.training1.core.entity.UnderCompanyEntity;
import com.training1.core.modules.service.BOXLoginService;
import com.training1.core.modules.service.ContractBaseService;
import com.training1.core.modules.service.UnderCompanyService;


@Controller
@RequestMapping("contractadvancedquery")
public class ContractAdvancedQueryController extends BaseController{
	@Resource
	private UnderCompanyService underCompanyService;
	@Resource
	private BOXLoginService bLoginService;
	@Resource
	private ContractBaseService contractBaseService;
	
	@RequestMapping("querysetting")
	public String contractterminate(){
		Integer userid = BOXLoginInfoUtil.getLoginInfo().getLoginId();
		Map<String,Object> map = new HashMap<>();
		map.put("pageId", 25);
		map.put("userId", userid.toString());
		if(bLoginService.getUserRole(map) != 0){
			return "huangyan/contractAdvancedQuery";
		}else{
			return "contract/notLimitsPage";
		}
	}
	@RequestMapping("findUnderCompany")
	@ResponseBody
	public List<UnderCompanyEntity> findUnderCompany(){
		UnderCompanyEntity uc = new UnderCompanyEntity();
		uc.setOrgName("全部");
		List<UnderCompanyEntity> list = new ArrayList<>();
		list.add(uc);
		List<UnderCompanyEntity> companylist = underCompanyService.findAllCompanyName();
		list.addAll(companylist);
		return list;
	}
	@RequestMapping("findlist")
	@ResponseBody
	public List<ContractBaseEntity> findlist(String customerName,String customerPhone,String status,String recom,
			String underCompany,String applstartTime,String applendTime,String loanstartTime,String loanendTime){
		Map<String,Object> map = new HashMap<>();
		map.put("customerName", customerName);
		map.put("customerPhone", customerPhone);
		map.put("status", status);
		map.put("recom", recom);
		map.put("underCompany", underCompany);
		map.put("applstartTime", applstartTime);
		map.put("applendTime", applendTime);
		map.put("loanstartTime", loanstartTime);
		map.put("loanendTime", loanendTime);
		List<ContractBaseEntity> list = contractBaseService.findList(map);
		return list;
	}
	@RequestMapping("findlistSUM")
	@ResponseBody
	public ContractBaseEntity findlistSUM(String customerName,String customerPhone,String status,String recom,
			String underCompany,String applstartTime,String applendTime,String loanstartTime,String loanendTime){
		Map<String,Object> map = new HashMap<>();
		map.put("customerName", customerName);
		map.put("customerPhone", customerPhone);
		map.put("status", status);
		map.put("recom", recom);
		map.put("underCompany", underCompany);
		map.put("applstartTime", applstartTime);
		map.put("applendTime", applendTime);
		map.put("loanstartTime", loanstartTime);
		map.put("loanendTime", loanendTime);
		return contractBaseService.findListSum(map);
	}
}
